package edu.qvtu.week3.controller;


import edu.qvtu.week3.entity.*;
import edu.qvtu.week3.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //查询所有学生
    @RequestMapping("/findAll")
    public List<Student> findAllStudent() {
        return studentService.list(null);
    }

    //通过id查询学生
    @RequestMapping("/findById")
    public Student findStudentById(@RequestParam Long id) {
        return studentService.getById(id);
    }

    //添加学生信息
    @RequestMapping("/save")
    public boolean saveStudent(@RequestBody Student student) {
        return studentService.save(student);
    }

    //修改学生信息
    @RequestMapping("/update")
    public boolean updateStudentById(@RequestBody Student student) {
        return studentService.updateById(student);
    }

    //根据id删除学生信息
    @RequestMapping("/removeById")
    public boolean removeStudentById(@RequestParam Long id) {
        //返回Boolean类型
        return studentService.removeById(id);
    }

    //批量删除学生信息
    @RequestMapping("/removeByIds")
    public boolean removeStudentByIds(@RequestBody List<Integer> ids) {
        return studentService.removeByIds(ids);
    }
}

